#ifndef AODV_PACKET_H
#define AODV_PACKET_H

#include "aodv_types.h"
#include "aodv_socket.h" // 添加此行以获取MAX_PACKET_SIZE

// 构建RREQ数据包
int build_rreq_packet(aodv_rreq *rreq, uint32_t rreq_id, uint32_t dest_addr, uint32_t dest_seq_num, uint32_t orig_addr, uint32_t orig_seq_num, uint8_t hop_count);

// 解析RREQ数据包
int parse_rreq_packet(const void *buffer, int len, aodv_rreq *rreq);

// 构建RREP数据包
int build_rrep_packet(aodv_rrep *rrep, uint32_t dest_addr, uint32_t dest_seq_num, uint32_t orig_addr, uint32_t orig_seq_num, uint8_t hop_count, uint32_t lifetime);

// 解析RREP数据包
int parse_rrep_packet(const void *buffer, int len, aodv_rrep *rrep);

// 构建RERR数据包
// 注意：RERR的构建可能需要动态处理不可达节点列表
int build_rerr_packet(aodv_rerr *rerr, uint8_t dest_count, const uint32_t *unreachable_addrs, const uint32_t *unreachable_seq_nums);

// 解析RERR数据包
int parse_rerr_packet(const void *buffer, int len, aodv_rerr *rerr, uint32_t *unreachable_addrs, uint32_t *unreachable_seq_nums);

// 构建Hello数据包
int build_hello_packet(aodv_hello *hello, uint32_t lifetime);

// 解析Hello数据包
int parse_hello_packet(const void *buffer, int len, aodv_hello *hello);

// 构建数据包
int build_data_packet(aodv_data_packet *data_pkt, uint32_t payload_len, const char *payload);

// 解析数据包
int parse_data_packet(const void *buffer, int len, aodv_data_packet *data_pkt);

#endif // AODV_PACKET_H